<su-form action="<%= form_path([:admin, @user]) %>"
         method="post"
         :init-fields="{authenticity_token: '<%= form_authenticity_token %>'}">
  <input name="utf8" type="hidden" value="✓">
  <input type="hidden" name="_method" value="<%= form_method @user %>">

  <%= form_validate @user %>

  <su-input type="password" label="<%= t "activerecord.attributes.user.password" %>" <%= 'required' if action_name != 'edit' %>  :validators="{minlength: 8}"
            name="user[password]" value="<%= @user.password %>">
    <p slot="help">密码最少为<code>8位字符</code></p>
    <%= '<p slot="help">修改时, 留空则不会修改密码.</p>'.html_safe if action_name=='edit' %>
  </su-input>
  <su-input type="text" label="<%= t "activerecord.attributes.user.name" %>" :validators="{minlength: 2}"
            name="user[name]" value="<%= @user.name %>" placeholder="真实姓名">
  </su-input>
  <su-input type="tel" label="<%= t "activerecord.attributes.user.phone" %>" :validators="['phone']" placeholder="手机号码"
            name="user[phone]" value="<%= @user.phone %>">
    <span slot="help"><code>11个字符</code>的手机号码,可当做账号登录</span>
  </su-input>
  <su-input type="text" label="<%= t "activerecord.attributes.user.email" %>" :validators="['email']"
            name="user[email]" value="<%= @user.email %>">
    <span slot="help">可以当做账号登陆</span>
  </su-input>
  <su-select label="<%= t "activerecord.attributes.user.roles" %>" multiple name="user[roles][]" :value="<%= @user.roles.ids %>">
    <% Role.all.each do |role| %>
        <option value="<%= role.id %>"><%= role.name %></option>
    <% end %>
  </su-select>
  <su-select label="<%= t "activerecord.attributes.user.area" %>" multiple name="user[area]" :value="<%= @user.area %>">
    <% CodeTable.where(name:'地域').each do |area| %>
        <option value="<%= area.id %>"><%= area.default_value %></option>
    <% end %>
  </su-select>
  <su-select label="<%= t "activerecord.attributes.user.group" %>" multiple name="user[group]" :value="<%= @user.group %>">
    <% CodeTable.where(name:'分组').each do |group| %>
        <option value="<%= group.id %>"><%= group.default_value %></option>
    <% end %>
  </su-select>
  <su-text label="<%= t "activerecord.attributes.user.remark" %>"
           name="user[remark]"><%= @user.remark %></su-text>
  <div class="clearfix form-actions">
    <%= render partial: 'shared/form/new_actions', locals: {options: {back_url: admin_users_path }} %>
  </div>
</su-form>